/**
 * <copyright>
 * </copyright>
 *
 * $Id$
 */
package editor.impl;

import editor.EditorPackage;
import editor.Root;
import editor.RootRelationship;

import org.eclipse.emf.common.notify.Notification;
import org.eclipse.emf.common.notify.NotificationChain;

import org.eclipse.emf.ecore.EClass;
import org.eclipse.emf.ecore.InternalEObject;

import org.eclipse.emf.ecore.impl.ENotificationImpl;
import org.eclipse.emf.ecore.impl.EObjectImpl;

/**
 * <!-- begin-user-doc -->
 * An implementation of the model object '<em><b>Root</b></em>'.
 * <!-- end-user-doc -->
 * <p>
 * The following features are implemented:
 * <ul>
 *   <li>{@link editor.impl.RootImpl#getName <em>Name</em>}</li>
 *   <li>{@link editor.impl.RootImpl#getOutgoingRoot <em>Outgoing Root</em>}</li>
 * </ul>
 * </p>
 *
 * @generated
 */
public class RootImpl extends EObjectImpl implements Root {
	/**
   * The default value of the '{@link #getName() <em>Name</em>}' attribute.
   * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
   * @see #getName()
   * @generated
   * @ordered
   */
	protected static final String NAME_EDEFAULT = null;

	/**
   * The cached value of the '{@link #getName() <em>Name</em>}' attribute.
   * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
   * @see #getName()
   * @generated
   * @ordered
   */
	protected String name = NAME_EDEFAULT;

	/**
   * The cached value of the '{@link #getOutgoingRoot() <em>Outgoing Root</em>}' reference.
   * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
   * @see #getOutgoingRoot()
   * @generated
   * @ordered
   */
	protected RootRelationship outgoingRoot;

	/**
   * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
   * @generated
   */
	protected RootImpl() {
    super();
  }

	/**
   * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
   * @generated
   */
	@Override
	protected EClass eStaticClass() {
    return EditorPackage.Literals.ROOT;
  }

	/**
   * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
   * @generated
   */
	public String getName() {
    return name;
  }

	/**
   * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
   * @generated
   */
	public void setName(String newName) {
    String oldName = name;
    name = newName;
    if (eNotificationRequired())
      eNotify(new ENotificationImpl(this, Notification.SET, EditorPackage.ROOT__NAME, oldName, name));
  }

	/**
   * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
   * @generated
   */
	public RootRelationship getOutgoingRoot() {
    if (outgoingRoot != null && outgoingRoot.eIsProxy())
    {
      InternalEObject oldOutgoingRoot = (InternalEObject)outgoingRoot;
      outgoingRoot = (RootRelationship)eResolveProxy(oldOutgoingRoot);
      if (outgoingRoot != oldOutgoingRoot)
      {
        if (eNotificationRequired())
          eNotify(new ENotificationImpl(this, Notification.RESOLVE, EditorPackage.ROOT__OUTGOING_ROOT, oldOutgoingRoot, outgoingRoot));
      }
    }
    return outgoingRoot;
  }

	/**
   * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
   * @generated
   */
	public RootRelationship basicGetOutgoingRoot() {
    return outgoingRoot;
  }

	/**
   * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
   * @generated
   */
	public NotificationChain basicSetOutgoingRoot(RootRelationship newOutgoingRoot, NotificationChain msgs) {
    RootRelationship oldOutgoingRoot = outgoingRoot;
    outgoingRoot = newOutgoingRoot;
    if (eNotificationRequired())
    {
      ENotificationImpl notification = new ENotificationImpl(this, Notification.SET, EditorPackage.ROOT__OUTGOING_ROOT, oldOutgoingRoot, newOutgoingRoot);
      if (msgs == null) msgs = notification; else msgs.add(notification);
    }
    return msgs;
  }

	/**
   * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
   * @generated
   */
	public void setOutgoingRoot(RootRelationship newOutgoingRoot) {
    if (newOutgoingRoot != outgoingRoot)
    {
      NotificationChain msgs = null;
      if (outgoingRoot != null)
        msgs = ((InternalEObject)outgoingRoot).eInverseRemove(this, EditorPackage.ROOT_RELATIONSHIP__SOURCE_ROOT, RootRelationship.class, msgs);
      if (newOutgoingRoot != null)
        msgs = ((InternalEObject)newOutgoingRoot).eInverseAdd(this, EditorPackage.ROOT_RELATIONSHIP__SOURCE_ROOT, RootRelationship.class, msgs);
      msgs = basicSetOutgoingRoot(newOutgoingRoot, msgs);
      if (msgs != null) msgs.dispatch();
    }
    else if (eNotificationRequired())
      eNotify(new ENotificationImpl(this, Notification.SET, EditorPackage.ROOT__OUTGOING_ROOT, newOutgoingRoot, newOutgoingRoot));
  }

	/**
   * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
   * @generated
   */
	@Override
	public NotificationChain eInverseAdd(InternalEObject otherEnd, int featureID, NotificationChain msgs) {
    switch (featureID)
    {
      case EditorPackage.ROOT__OUTGOING_ROOT:
        if (outgoingRoot != null)
          msgs = ((InternalEObject)outgoingRoot).eInverseRemove(this, EditorPackage.ROOT_RELATIONSHIP__SOURCE_ROOT, RootRelationship.class, msgs);
        return basicSetOutgoingRoot((RootRelationship)otherEnd, msgs);
    }
    return super.eInverseAdd(otherEnd, featureID, msgs);
  }

	/**
   * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
   * @generated
   */
	@Override
	public NotificationChain eInverseRemove(InternalEObject otherEnd, int featureID, NotificationChain msgs) {
    switch (featureID)
    {
      case EditorPackage.ROOT__OUTGOING_ROOT:
        return basicSetOutgoingRoot(null, msgs);
    }
    return super.eInverseRemove(otherEnd, featureID, msgs);
  }

	/**
   * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
   * @generated
   */
	@Override
	public Object eGet(int featureID, boolean resolve, boolean coreType) {
    switch (featureID)
    {
      case EditorPackage.ROOT__NAME:
        return getName();
      case EditorPackage.ROOT__OUTGOING_ROOT:
        if (resolve) return getOutgoingRoot();
        return basicGetOutgoingRoot();
    }
    return super.eGet(featureID, resolve, coreType);
  }

	/**
   * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
   * @generated
   */
	@Override
	public void eSet(int featureID, Object newValue) {
    switch (featureID)
    {
      case EditorPackage.ROOT__NAME:
        setName((String)newValue);
        return;
      case EditorPackage.ROOT__OUTGOING_ROOT:
        setOutgoingRoot((RootRelationship)newValue);
        return;
    }
    super.eSet(featureID, newValue);
  }

	/**
   * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
   * @generated
   */
	@Override
	public void eUnset(int featureID) {
    switch (featureID)
    {
      case EditorPackage.ROOT__NAME:
        setName(NAME_EDEFAULT);
        return;
      case EditorPackage.ROOT__OUTGOING_ROOT:
        setOutgoingRoot((RootRelationship)null);
        return;
    }
    super.eUnset(featureID);
  }

	/**
   * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
   * @generated
   */
	@Override
	public boolean eIsSet(int featureID) {
    switch (featureID)
    {
      case EditorPackage.ROOT__NAME:
        return NAME_EDEFAULT == null ? name != null : !NAME_EDEFAULT.equals(name);
      case EditorPackage.ROOT__OUTGOING_ROOT:
        return outgoingRoot != null;
    }
    return super.eIsSet(featureID);
  }

	/**
   * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
   * @generated
   */
	@Override
	public String toString() {
    if (eIsProxy()) return super.toString();

    StringBuffer result = new StringBuffer(super.toString());
    result.append(" (name: ");
    result.append(name);
    result.append(')');
    return result.toString();
  }

} //RootImpl
